/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mapping;
import java.sql.ResultSet;
import mapping.SqlLib;
import entreprise.Service;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Quoc-Khai
 */
public class DBService {
    public Service getService(int serviceID) throws SQLException{
        Service iService = new Service();
        String selectQuery;
        selectQuery = "SELECT * FROM service WHERE serviceID='"+serviceID+"'";
        
        SqlLib connec = new SqlLib();
        if (connec.initConnection()) {
            ResultSet sqlResultSet = connec.getDataFromQuery(selectQuery);
            
            while(sqlResultSet.next()) {
               iService.setServiceID(sqlResultSet.getString("serviceID")); 
               iService.setServiceName(sqlResultSet.getString("serviceName")); 
               iService.setServicePrice(sqlResultSet.getString("servicePrice")); 
               iService.setServiceDescription(sqlResultSet.getString("serviceDescription"));   
            }
        } else {
            System.out.println("Service not found!");
        } 
        return iService;
    }
    public boolean createService(Service service){
        //TODO;
         String insertQuery;
        insertQuery = "INSERT INTO service (serviceName, servicePrice, serviceDescription) VALUES ('" + service.getServiceName()+ "','" + service.getServicePrice()+ "','" + service.getServiceDescription() + "')";
        SqlLib connec = new SqlLib();
        
        if (connec.initConnection()) {
            connec.execQuery(insertQuery);
            System.out.println("Insert Service success!");
            return true;
        }
        return false;
    }
    public boolean updateService(Service service){
        //TODO
        String updateQuery;
        updateQuery = "UPDATE service SET serviceName='" + service.getServiceName()+ "', servicePrice=" + service.getServicePrice()
                +",serviceDescription='" + service.getServiceDescription()+ "' WHERE serviceID='"+service.getServiceID()+"'";
        
        SqlLib connec = new SqlLib();
        
        if (connec.initConnection()) {
            connec.execQuery(updateQuery);
            System.out.println("Update Service success!");
            return true;
        } 
        return false;
    }
    public boolean deleteService(int serviceID){
        //TODO
        String deleteQuery;
        deleteQuery = "DELETE FROM service WHERE serviceID='"+serviceID+"'"; 
        SqlLib connec = new SqlLib();
        
        if (connec.initConnection()) {
            connec.execQuery(deleteQuery);
            System.out.println("Delete Service success!");
            return true;
        }
        return false;
    }    
    public List<Service> getServices(String conditions){
        List<Service> services=null;
        //TODO
        return services;
    }    
}
